package cn.gok.client.controller;

import cn.gok.client.service.AdressSercice;
import cn.gok.common.enums.ResultEnum;
import cn.gok.common.resp.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shikundai
 * @Date 2020/10/20
 * @Time 16:56
 * @description 地址获取（城市、省份、区域）的相关控制器曾操作
 */
@RestController
@RequestMapping("/client/adress")
public class AdressController {
    /**
     * @author shikundai
     * @date 2020/11/1
     * @time 10:59
     * @description 注入地址的业务逻辑层
     */
    @Autowired
    private AdressSercice adressSercice;

    /**
     * @author shikundai
     * @date 2020/11/1
     * @time 11:00
     * @description 获取所有省份的地址
     */
    @GetMapping("/getAllProvince")
    public Result getAllProvince() {
//        创建返回对象
        Result result=new Result();
//        设置状态码为成功
        result.setCode(ResultEnum.SYSTEM_NORMAL_SUCCESS.getCode());
//        设置数据
        result.setData(adressSercice.getAllProvince());
//        返回结果
        return result;
    }

    /**
     * @author shikundai
     * @date 2020/11/1
     * @time 15:10
     * @description 通过省份ID获得它的城市信息
     */
    @GetMapping("/getCities")
    public Result getCitiesByProvinceId(@RequestParam("provinceId") String provinceId){
        Result result=new Result();
        //设置返回码成功
        result.setCode(ResultEnum.SYSTEM_NORMAL_SUCCESS.getCode());
        //设置数据
        result.setData(adressSercice.getCityByProvinceId(provinceId));
        return result;
    }
    /**
     * @author shikundai
     * @date 2020/11/1
     * @time 16:13
     * @description  通过城市ID获取区域信息
     */
    @GetMapping("/getArea")
    public Result getAreaByCityId(@RequestParam("cityId")String cityId){
        Result result=new Result();
        //设置状态码为成功
        result.setCode(ResultEnum.SYSTEM_NORMAL_SUCCESS.getCode());
        //存放区域数据
        result.setData(adressSercice.getAreaByCityId(cityId));
        return result;
    }
}
